 <? /*
        // File: quotawarn.inc.phps
        // Purpose: Scan users quota and send warning email if hd_used>hd
        // Creation: 2004-11-14
        // Author: Kenneth Lee <kenneth@nexgear.com>
        // Edited By: Peter Drake
        */
// This has been moved to hdquota.mod.phps and bwquota.mod.phps
/*
// quota warning messages
$T['diskquotasubject'] = "Disk Quota Limit Exceeded";
$T['transferquotasubject'] = "Transfer Quota Limit Exceeded";
$T['userquotabody'] = "Please note that you have exceeded the disk quota limit set by your System Administrator. You are using %HDUSED%MB with only %HD%MB allocated. You will receive this email daily whenever your quota is exceeded. To make more space available, delete any items that you are no longer using or move them to your personal computer. Items in all your mailbox folders including the INBOX, Trash and Sent Items folders count against your size limits. You must empty the Trash folder after deleting items or the space will not be freed. You may check your disk quota from the PersonalCP page in WebCP. Please contact your System Administrator for more information.";
$T['domainquotabody'] = "Please note that your domain: %DOMAIN% has exceeded the disk quota limit set by your System Administrator. You are using %HDUSED%MB with only %HD%MB allocated. You will receive this email daily whenever your quota is exceeded. To make more space available, delete any items that you are no longer using or move them to your personal computer. Items in all your users mailbox folders including the INBOX, Trash and Sent Items folders count against your size limits. They must empty the Trash folder after deleting items or the space will not be freed. You may check your disk quota from the DomainCP page in WebCP. Please contact your System Administrator for more information.";
$T['domaintransferbody'] = "Please note that your domain: %DOMAIN% has exceeded the transfer limit set by your System Administrator. You have used %TRANSFERUSED%GB transfer with only %TRANSFER%GB allocated. You will receive this email daily whenever your transfer quota is exceeded. You may check your transfer quota from the DomainCP page in WebCP. Please contact your System Administrator for more information.";
$T['resellerquotabody'] = "Please note that your reseller account: %NAME% has exceeded the disk quota limit set by your System Administrator. Your domains are using %HDUSED%MB with only %HD%MB allocated. You will receive this email daily whenever your quota is exceeded. To make more space available, delete any domains that you are no longer using. Items in all your users mailbox folders including the INBOX, Trash and Sent Items folders count against your size limits. They must empty the Trash folder after deleting items or the space will not be freed. You may check your disk quota from the ResellerCP page in WebCP. Please contact your System Administrator for more information.";
$T['resellertransferbody'] = "Please note that your reseller account: %NAME% has exceeded the transfer limit set by your System Administrator. Your domains have used %TRANSFERUSED%GB transfer with only %TRANSFER%GB allocated. You will receive this email daily whenever your transfer quota is exceeded. You may check your transfer quota from the ResellerCP page in WebCP. Please contact your System Administrator for more information.";

webcp_log(2,0,'quotawarn',"begining quota warning script",0);

if ($cfg['sendquotaemails']) {

// Start User Quota check
$dbp = mysql_query("SELECT users.username, users.hd, users.hd_used, domains.domain FROM users inner join domains ON users.id = domains.id WHERE users.type != 'demo' AND users.hd_used > users.hd AND users.hd != -1 AND users.suspend = 'false'");

while ($data = mysql_fetch_array($dbp)) {
	$search[] = "%HDUSED%";
	$search[] = "%HD%";
	$replace[] = $data['hd_used'];
	$replace[] = $data['hd'];
	$body = str_replace($search, $replace, $T['userquotabody']);
	mail($data["username"]."@".$data["domain"], $T['diskquotasubject'], $body, "From: noreply@".$cfg['sysname']);
	webcp_log(2,0,'quotawarn',"user disk quota warning sent to ".$data["username"],0);
}


// Start domain quota check.
$dbp = mysql_query("SELECT domains.email, domains.hd, domains.hd_used, domains.domain FROM domains WHERE domains.hd_used > domains.hd AND domains.hd != -1 AND domains.type = 'domain' AND domains.suspended = 'false'");

while ($data = mysql_fetch_array($dbp)) {
	$search[] = "%DOMAIN%";
	$search[] = "%HDUSED%";
	$search[] = "%HD%";
	$replace[] = $data['domain'];
	$replace[] = $data['hd_used'];
	$replace[] = $data['hd'];
	$body = str_replace($search, $replace, $T['domainquotabody']);
	mail($data["email"], $T['diskquotasubject'], $body, "From: noreply@".$cfg['sysname']);
	webcp_log(2,0,'quotawarn',"domain disk quota warning sent to ".$data['domain'],0);
}

// Start domain transfer check
$dbp = mysql_query("SELECT domains.email, domains.transfer, domains.transfer_used, domains.domain FROM domains WHERE domains.transfer_used > domains.transfer AND domains.transfer != -1 AND domains.type = 'domain' AND domains.suspended = 'false'");

while ($data = mysql_fetch_array($dbp)) {
	$search[] = "%DOMAIN%";
	$search[] = "%TRANSFERUSED%";
	$search[] = "%TRANSFER%";
	$replace[] = $data['domain'];
	$replace[] = $data['transfer_used'];
	$replace[] = $data['transfer'];
	$body = str_replace($search, $replace, $T['domaintransferbody']);
	mail($data["email"], $T['transferquotasubject'], $body, "From: noreply@".$cfg['sysname']);
	webcp_log(2,0,'quotawarn',"domain transfer quota warning sent to ".$data['domain'],0);
}

// Start reseller quota check.
$dbp = mysql_query("SELECT resellers.name, resellers.email, sum(domains.hd_used) AS hdused, resellers.hd FROM resellers inner join domains on resellers.id = domains.owner WHERE resellers.hold = 'false' GROUP BY resellers.name");

while ($data = mysql_fetch_array($dbp)) {
	echo $data["hdused"]." > ".$data["hd"];
	if ($data["hdused"] > $data["hd"] && $data["hd"] != -1) {
		$search[] = "%NAME%";
		$search[] = "%HDUSED%";
		$search[] = "%HD%";
		$replace[] = $data['name'];
		$replace[] = $data['hdused'];
		$replace[] = $data['hd'];
		$body = str_replace($search, $replace, $T['resellerquotabody']);
		mail($data["email"], $T['diskquotasubject'], $body, "From: noreply@".$cfg['sysname']);
		webcp_log(2,0,'quotawarn',"reseller disk quota warning sent to ".$data['name'],0);
	}
}

// Start reseller transfer check
$dbp = mysql_query("SELECT resellers.name, resellers.email, sum(domains.transfer_used) AS transferused, resellers.transfer FROM resellers inner join domains on resellers.id = domains.owner WHERE resellers.hold = 'false' GROUP BY resellers.name");

while ($data = mysql_fetch_array($dbp)) {
	if ($data["transferused"] > $data["transfer"] && $data["transfer"] != -1) {
		$search[] = "%NAME%";
		$search[] = "%TRANSFERUSED%";
		$search[] = "%TRANSFER%";
		$replace[] = $data['name'];
		$replace[] = $data['transferused'];
		$replace[] = $data['transfer'];
		$body = str_replace($search, $replace, $T['resellertransferbody']);
		mail($data["email"], $T['transferquotasubject'], $body, "From: noreply@".$cfg['sysname']);
		webcp_log(2,0,'quotawarn',"reseller transfer quota warning sent to ".$data['name'],0);
	}
}

}
*/
?>
